//
//  RegisterVCOfFVQM.m
//  FVQuickMessage
//
//  Created by ZMQ on 16/8/11.
//  Copyright © 2016年 zty. All rights reserved.
//

#import "RegisterVCOfFVQM.h"


@interface RegisterVCOfFVQM ()

@property (nonatomic, retain)UIButton *buttonOfFanHui;
@property (nonatomic, retain)UILabel *labelOfDL;

@property (nonatomic, retain) UIImageView *imageViewOfShadw;
@property (nonatomic, retain) UIView *viewOfShadow;//加暗度，让标题显现，高亮

@property (nonatomic, retain)UITextField *textFieldOfUser;
@property (nonatomic, retain)UITextField *textFieldOfPassword;

@property (nonatomic, retain)UIView *viewOfUser;
@property (nonatomic, retain)UIView *viewOfPassword;

@property (nonatomic, retain) UIButton *buttonOfRE;


@end

@implementation RegisterVCOfFVQM

- (void)viewDidLoad {
    [super viewDidLoad];


    [self config];
}


-(void)config{
    
    
    //图片
    self.imageViewOfShadw = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:_imageViewOfShadw];
   
    self.imageViewOfShadw.image = [UIImage imageNamed:@"IMG_2104"];
    

    //阴影
    self.viewOfShadow = [[UIView alloc]init];
    [self.imageViewOfShadw addSubview:_viewOfShadow];
    self.viewOfShadow.backgroundColor = [UIColor colorWithRed:38 / 255.0 green:38 / 255.0 blue:38 / 255.0 alpha:0.7];
    [self.viewOfShadow mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.equalTo(self.imageViewOfShadw);
        
    }];


    
    //返回
    self.buttonOfFanHui = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:_buttonOfFanHui];
    
    [self.buttonOfFanHui setTitle:@"返回" forState:UIControlStateNormal];
    self.buttonOfFanHui.titleLabel.font = [UIFont systemFontOfSize:12];
    
    [self.buttonOfFanHui addTarget:self action:@selector(ClickFanHui:) forControlEvents: UIControlEventTouchUpInside];
    self.buttonOfFanHui.tintColor = [UIColor colorWithRed:81 / 256.0  green:154 / 256.0  blue: 163 / 256.0  alpha:1];
    self.buttonOfFanHui.backgroundColor = [UIColor whiteColor];
    self.buttonOfFanHui.layer.masksToBounds = YES;
    self.buttonOfFanHui.layer.cornerRadius = 15;
    [self.buttonOfFanHui mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).with.offset(30);
        make.left.equalTo(self.view).with.offset(30);
        make.width.equalTo(@30);
        make.height.equalTo(@30);
        
    }];
    
    //欢迎语
    self.labelOfDL = [[UILabel alloc]init];
    [self.view addSubview:_labelOfDL];
    self.labelOfDL.text = @"欢迎注册快信账号";
    self.labelOfDL.font = [UIFont systemFontOfSize:15];
    self.labelOfDL.textColor = [UIColor whiteColor];
    self.labelOfDL.textAlignment = NSTextAlignmentCenter;//居中
    [self.labelOfDL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).with.offset(30);
        make.centerX.equalTo(self.view);
        make.width.offset(150);
        make.height.offset(40);
        
    }];
    
    
    
    /**账号*/
    self.textFieldOfUser = [[UITextField alloc]init];
    [self.view addSubview:_textFieldOfUser];
    self.textFieldOfUser.placeholder = @"点击输入手机号/用户名/Email进行注册";
    self.textFieldOfUser.font = [UIFont systemFontOfSize:13];
    [self.textFieldOfUser setValue:[UIColor colorWithRed:200 / 256.0  green:200/ 256.0  blue: 200/ 256.0  alpha:1] forKeyPath:@"_placeholderLabel.textColor"];
    
    self.textFieldOfUser.textColor = [UIColor whiteColor];
    self.textFieldOfUser.textAlignment = NSTextAlignmentCenter;
    
    [self.textFieldOfUser mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).with.offset(200);
        make.left.equalTo(self.view).with.offset(10);
        make.right.equalTo(self.view).with.offset(-10);
        make.height.equalTo(@30);
        
    }];
    
    
    self.viewOfUser = [[UIView alloc]init];
    [self.view addSubview:_viewOfUser];
    self.viewOfUser.backgroundColor = [UIColor whiteColor];
    [self.viewOfUser mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.textFieldOfUser.mas_bottom).with.offset(1);
        make.left.equalTo(self.view).with.offset(60);
        make.right.equalTo(self.view).with.offset(-60);
        make.height.offset(1);
        
        
    }];
    
    
    
    /**密码*/
    self.textFieldOfPassword = [[UITextField alloc]init];
    [self.view addSubview:_textFieldOfPassword];
    self.textFieldOfPassword.placeholder = @"输入密码进行注册";
    self.textFieldOfPassword.font = [UIFont systemFontOfSize:13];
    [self.textFieldOfPassword setValue:[UIColor colorWithRed:200 / 256.0  green:200 / 256.0  blue: 200 / 256.0  alpha:1]forKeyPath:@"_placeholderLabel.textColor"];
    self.textFieldOfPassword.textColor = [UIColor whiteColor];
     self.textFieldOfPassword.textAlignment = NSTextAlignmentCenter;
    [self.textFieldOfPassword mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewOfUser.mas_bottom).with.offset(20);
        make.left.equalTo(self.view).with.offset(10);
        make.right.equalTo(self.view).with.offset(-10);
        make.height.equalTo(@30);
        
    }];
    
    
    self.viewOfPassword = [[UIView alloc]init];
    [self.view addSubview:_viewOfPassword];
    self.viewOfPassword.backgroundColor = [UIColor whiteColor];
    [self.viewOfPassword mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.textFieldOfPassword.mas_bottom).with.offset(1);
        make.left.equalTo(self.view).with.offset(60);
        make.right.equalTo(self.view).with.offset(-60);
        make.height.offset(1);
        
    }];
    
    

    /**注册*/
    self.buttonOfRE = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:_buttonOfRE];
    [self.buttonOfRE setTitle:@"马上注册" forState: UIControlStateNormal];
    [self.buttonOfRE addTarget:self action:@selector(ClickZuCe:) forControlEvents: UIControlEventTouchUpInside];
    self.buttonOfRE.tintColor = [UIColor whiteColor];
    self.buttonOfRE.backgroundColor = [UIColor whiteColor];
    
    self.buttonOfRE.titleLabel.font = [UIFont systemFontOfSize:12];
    self.buttonOfRE.tintColor  =[UIColor colorWithRed:81 / 256.0  green:154 / 256.0  blue: 163 / 256.0  alpha:1];
    self.buttonOfRE.layer.cornerRadius = 10;
    [self.buttonOfRE mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewOfPassword.mas_bottom).with.offset(80);
        make.centerX.equalTo(self.view);
        make.width.equalTo(@120);
        make.height.equalTo(@30);
        
    }];

    
   
    
    
}


-(void)ClickFanHui:(UIButton *)btn{
    
    [btn setShowsTouchWhenHighlighted:YES];//按钮发光
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_textFieldOfUser resignFirstResponder];
    [_textFieldOfPassword resignFirstResponder];
}



-(void)ClickZuCe:(UIButton *)btn{
    
    
        [btn setShowsTouchWhenHighlighted:YES];//按钮发光
    
    
        //  登陆和注册有3种方法: 1. 同步方法 2. 通过delegate回调的异步方法。3.block异步方法
        //其中官方推荐使用block异步方法,所以我这里就用block异步方法
    
        //开始注册
        [[EaseMob sharedInstance].chatManager asyncRegisterNewAccount:_textFieldOfUser.text password:_textFieldOfPassword.text withCompletion:^(NSString *username, NSString *password, EMError *error) {
            if (!error) {
                NSLog(@"注册成功");
    
    
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"恭喜你注册成功,请返回登录" preferredStyle: UIAlertControllerStyleAlert];
    
                UIAlertAction *alertAction  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    
    
    
                }];
    
                [alertController addAction:alertAction];
    
                [self presentViewController:alertController animated:YES completion:^{
    
                }];
              
                
                self.str(_textFieldOfUser.text);
                self.string(_textFieldOfPassword.text);
                
    
            }else{
                NSLog(@"%@",error);
                
                
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"注册失败哎,请重新注册" preferredStyle: UIAlertControllerStyleAlert];
                
                UIAlertAction *alertAction  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    
                    
                    
                }];
                
                [alertController addAction:alertAction];
                
                [self presentViewController:alertController animated:YES completion:^{
                    
                }];

                
                
                
            }
        } onQueue:dispatch_get_main_queue()];
    
    
    
    
}





@end
